<?php


namespace app\im\live\auth;

use app\im\model\imLiveUserModel;
use iflow\Container\implement\annotation\tools\data\Inject;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\PostMapping;

#[Controller('im/rtmp_auth')]
class rtmpAuth {

    #[Inject]
    public imLiveUserModel $imLiveUserModel;

    /**
     * 验证是否为主播 / NGINX RTMP 验证模块
     * @param string $key
     * @return Response
     */
    #[PostMapping]
    public function authIsLiveAdmin(string $key): Response
    {
        $live = $this->imLiveUserModel -> getLiveByHashKey($key);
        if ($live) {
            $this->imLiveUserModel -> updateInfo([
                'is_live' => 1
            ], ['live_hash_key' => $key]);

            return message() -> setIsRest() -> success('success');
        }
        return message() -> setIsRest() -> unauthorized_error('unauthorized_error');
    }

}